<%@page import="java.util.LinkedList"%>
<%@page import="com.itsm.v17.entity.Prize"%>
<%@page import="org.jfaster.ProxyTemplate"%>
<%@page import="org.jfaster.Template"%>
<%@page import="com.itsm.v17.entity.PrizeRecord"%>
<%@page import="java.util.List"%>
<%@ page pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String userId=request.getParameter("userId");
String handled=request.getParameter("handled");
String startDate=request.getParameter("startDate");
String endDate=request.getParameter("endDate");
String message =(String)request.getAttribute("message");
List list =(List)request.getAttribute("list");
if(list==null){list=new LinkedList();}
if(userId==null){userId="";}
if(handled==null){handled="";}
if(startDate==null){startDate="";}
if(endDate==null){endDate="";}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>抽奖清单管理</title>
<link href="<%=basePath%>js/DatePicker/skin/WdatePicker.css" rel="stylesheet" type="text/css">
<link href="<%=basePath%>css/home.css" type="text/css" rel="stylesheet" />
<script src="<%=basePath%>js/DatePicker/WdatePicker.js" type="text/javascript"></script>
<link href="<%=basePath%>js/DatePicker/skin/WdatePicker.css" rel="stylesheet" type="text/css">
<script src="<%=basePath%>itsm/js/ajax.js"></script>
<script src="<%=basePath%>itsm/js/ajax.form.js"></script>
<script src="<%=basePath%>itsm/js/formValidate.js"></script>
<script src="<%=basePath%>itsm/js/select.js"></script>
<script src="<%=basePath%>itsm/js/reSet.js"></script>
<style>
.tableblue00 td{
padding:5px;
}
.bbzxbg2:hover{
background:#dadada;
}
.columnHead td{
background:#e7eaed;
}
</style>
<script>
function query()
{
	var startDate=document.getElementById("startDate").value;
	var endDate=document.getElementById("endDate").value;
	var userId=document.getElementById("userId").value;
	var handled=document.getElementById("handled").value;
	location.href="<%=path%>/itsm17/prize/list?startDate="+startDate+"&endDate="+endDate+"&handled="+handled+"&userId="+userId;
}
</script>
</head>
<body style="padding:5px;margin:0px;">
	    <table width="100%" cellspacing="1" cellpadding="0" border="0" bgcolor="#D6E6F4" class="tableblue00">
                            <tbody>
                            <tr class="bbzxbg2">
                              <td colspan=3 >
                              	 用户ID： <input type="text" id="userId" value="<%=userId%>"  ondblclick="javascript:this.value='';" />
                              	 &nbsp; &nbsp; &nbsp; &nbsp;
                              	  处理状态:
                              	  <select id="handled" name="handled" >
                              	  	<option value="" <%if("".equals(handled)){out.print("selected='selected'");} %> >全部</option>
                              	 	<option value="1" <%if("1".equals(handled)){out.print("selected='selected'");} %>>已处理</option>
                              	 	<option value="0" <%if("0".equals(handled)){out.print("selected='selected'");} %>>未处理</option>
                              	 </select>
                              	 &nbsp; &nbsp; &nbsp; &nbsp;
                              	 起点时间： <input type="text" id="startDate" value="<%=startDate%>"  onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" />
                              	 &nbsp; &nbsp; &nbsp; &nbsp;
                              	 截止时间： <input type="text" id="endDate" value="<%=endDate%>" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" />
                              	 &nbsp; &nbsp; &nbsp; &nbsp;
                              	 
                              	 <a class="actionbutton"  href='javascript:;' onclick="query()" class="menudiv" style="margin-right: 10px;">查询</a>
                              	 &nbsp;&nbsp;&nbsp; &nbsp;
                              	 <a class="actionbutton"  href='javascript:;' onclick="setHandle(1)" class="menudiv" style="margin-right: 10px;">设为已处理</a>
                              	 &nbsp;&nbsp;&nbsp; &nbsp;
                              	 <a class="actionbutton"  href='javascript:;' onclick="setHandle(0)" class="menudiv" style="margin-right: 10px;">设为未处理</a>
                              	 &nbsp;&nbsp;&nbsp; &nbsp;
                              	 
                              	 <span id="message"><%=message%></span>
   	
                              </td>
                            </tr></tbody>
          </table>
                     <br/>
                     
<table width="100%" cellspacing="1" cellpadding="0" border="0" bgcolor="#D6E6F4" class="tableblue00 ry_box" id="datalist" >
   <tbody>
   <tr class="columnHead" align="center" >
                <td width="50px"><input type="checkbox" onclick="choose(this)"/></td>
                <td >序号</td>
                <td align="left">中奖名称</td>
                <td align="left">用户ID</td>
                <td align="left">用户名称</td>
                <td align="left">中奖时间</td>
                <td align="left">是否处理</td>
         </tr>
   <%
   		int handledCount=0,unHandledCount=0;
   Template template=new ProxyTemplate(Prize.class).getInstance();
   try
   {
	   for(int i=0;i<list.size();i++)
  		{
  			PrizeRecord record=(PrizeRecord)list.get(i);
  			Prize prize=(Prize)template.get(record.getAwardItemId());
  			String prizeName="";
  			if(prize != null)
  			{
  				prizeName=prize.getName();
  				if((1 == record.getHandled()))
  	  			{
  	  				handledCount=handledCount+prize.getSpace();
  	  			}else
  	  			{
  	  				unHandledCount=unHandledCount+prize.getSpace();
  	  			}
  			}
  			
  			%>
  				<tr class="bbzxbg2">
  				<td ><input type="checkbox" value="<%=record.getId()%>" id="cbox<%=i%>" /></td>
  				<td><%=(i+1)%></td>
               <td><%=prizeName%></td>
               <td align="left"><a href="<%=path%>/itsm17/prize/list?userId=<%=record.getUserId()%>"><%=record.getUserId()%></a></td>
               <td align="left"><a href="<%=path%>/itsm17/prize/list?userId=<%=record.getUserId()%>"><%=record.getUserName()%></a></td>
               <td align="left"><%=record.getDateTime()%></td>
               <td align="left"><%if(0 == record.getHandled()){out.print("未处理");}else{out.print("<font color=blue><b>已处理</b></font>");}%></td>
        </tr>
  			<%
  		}
	   
   }catch(Exception exception)
   {
	   exception.printStackTrace();
	   out.println("<tr><td colspan=7>"+exception.toString()+"</td></tr>");
   }finally
   {
	   template.close();
   }
   %>
          <tr class="bbzxbg2">
                <td colspan=7 align="left">&nbsp;已处理<%=handledCount%>M &nbsp;&nbsp;&nbsp;&nbsp;未处理<%=unHandledCount%>M</td>
         </tr>               
 </tbody>
</table>            
<script>
function choose(obj)
{
	//log("checked="+obj.checked);
	var trs=document.getElementById("datalist").getElementsByTagName("tr");
	//log("trs="+trs.length);
	for(var i=0;i<(trs.length-2);i++)
	{
		//log("cbox"+i);
		document.getElementById("cbox"+i).checked=obj.checked;
	}
}
function setHandle(h)
{
	get("message").innerHTML='';
	var trs=document.getElementById("datalist").getElementsByTagName("tr");
	var count=0;
	var ids="";
	for(var i=0;i<(trs.length-2);i++)
	{
		var bx=document.getElementById("cbox"+i);
		if(bx.checked)
		{
			if(count == 0)
			{
				ids=bx.value;
			}else
			{
				ids=ids+","+bx.value;
			}
			count++;
		}
	}	
	if(count == 0)
	{
		get("message").innerHTML='<font color=red>请选择要操作的项</font>';
		return;
	}
	new ajax({'url':'<%=path%>/itsm17/prize/setHandle','params':'handle='+h+"&ids="+ids,'success':function(data)
		{
			var json=toJson(data);
			if(json.result)
			{
				location.reload();
			}else
			{
				//alert(json.message);
				get("message").innerHTML='<font color=red>'+json.message+'</font>';
			}
		}});
}
</script>                    
                     
</body>
</html>